#include "CEngine.h"

USING_NS_CC;

CEngine::CEngine()
{
}

/**
 * Adds engine animation to cache.
 *
 * @param frameNamePrefix The starting frame prefix and animation name for the engine.
 * @param pSpriteSheet This parameter is created and released by the MainLayer.
 *
 * @return true if the sprite was initialized without problems, false otherwise.
 */
bool
CEngine::init(char* frameNamePrefix, CCSpriteBatchNode* pSpriteSheet, b2World* pWorld)
{
	if(!CAnimatedObject::init(frameNamePrefix, pSpriteSheet, pWorld))
	{
		return false;
	}

	CAnimationProperties* engineAnim = new CAnimationProperties();
	engineAnim->_animationName = frameNamePrefix;
	engineAnim->_frameCount = 2;
	engineAnim->_delay = 0.1f;
	CAnimatedObject::addAnimation(engineAnim);

	return true;
}

void
CEngine::animNormal()
{
	//Create animation
	CCAnimation* pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("shipEngineNormal");
	cocos2d::CCAction* pAnimationAction = CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(pAnimation));
	this->stopAllActions();
	this->runAction(pAnimationAction);
}

void
CEngine::animForward()
{
	this->stopAllActions();
	this->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("shipEngineForward1.png"));
}

void
CEngine::animBack()
{
	this->stopAllActions();
	this->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("shipEngineBack1.png"));
}
